package com.vn.gofriends.ui;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.DatePicker;
import android.widget.EditText;

public class MyEditTextDatePicker implements OnClickListener, OnDateSetListener {
	EditText _editText;
	private int _day;
	private int _month;
	private int _year;
	private Context _context;
	Calendar calendar;
	public MyEditTextDatePicker(Context context, EditText editTextView) {
		//Activity act = (Activity) context;
		///this._editText = (EditText) act.findViewById(editTextViewID);
		this._editText = editTextView;
		this._editText.setOnClickListener(this);
		this._context = context;
		calendar = Calendar.getInstance();
	}

	@Override
	public void onDateSet(DatePicker view, int year, int monthOfYear,
			int dayOfMonth) {
		_year = year;
		_month = monthOfYear;
		_day = dayOfMonth;
		updateDisplay();
	}

	@Override
	public void onClick(View v) {
		new DatePickerDialog(_context, this, calendar.get(Calendar.YEAR),
				calendar.get(Calendar.MONTH),
				calendar.get(Calendar.DAY_OF_MONTH)).show();

	}

	// updates the date in the birth date EditText
	private void updateDisplay() {
		_editText.setText(new StringBuilder().append(_year).append("-")
				.append(_month + 1).append("-").append(_day).append(" "));
	}
}